using System.Collections;
using System.Collections.Generic;
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GameManager : MonoBehaviour
{
    public List<GameObject> targets;
    private float spawnRate = 1f;
    public TMP_Text scoreTest;
    public int score = 0;
    public TMP_Text gameOver;
    public GameObject gamerOverPanel;

    public Button restartButton;
    public bool over;
    public List<Button> diffcultyButton;
    

    private void Start()
    {
        

        scoreTest.text = "Score:" + score;
        restartButton.onClick.AddListener(RestarGame);
        //for (int i = 0; i< diffcultyButton.Count; i++)
        //{
        //    diffcultyButton[i].onClick.AddListener(SetDiffculty);
        //}

    }

    public void StartGame(int diffculty)
    {
        spawnRate = 1f / diffculty;
        StartCoroutine(SpawnTarget());
    }

    IEnumerator SpawnTarget()
    {
        while (!gameOver)
        {
            yield return new WaitForSeconds(spawnRate);
            int index = Random.Range(0, targets.Count);
            Instantiate(targets[index]);
        }
    }

    public void UpdateScore(int scoreToAdd)
    {
        score += scoreToAdd;
        scoreTest.text = "Score:" + score;
    }

    public void GameOver()
    {
        gamerOverPanel.gameObject.SetActive(true);
        over = true;
    }


    public void RestarGame()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }


}
